//
//  TLST_jokeCell.m
//  Travel_World
//
//  Created by lanou on 15/10/14.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLST_jokeCell.h"
#import "TLST_jokeModel.h"
#import "TLST_jokeFrameModel.h"

@implementation TLST_jokeCell
+ (instancetype)cellWithTabelView:(UITableView *)tableView{
    static NSString *ID = @"myJokeCell";
    TLST_jokeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TLST_jokeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.profile_imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.profile_imageView];
        self.profile_imageView.layer.cornerRadius = 25*WID;
        self.profile_imageView.layer.masksToBounds = YES;
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.nameLabel];
        
        self.createdLabel = [[UILabel alloc] init];
        self.createdLabel.font = [UIFont systemFontOfSize:14];
        self.createdLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.createdLabel];
        
        self.textLabell = [[UILabel alloc] init];
        self.textLabell.numberOfLines = 0;
        self.textLabell.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.textLabell];
        
        self.loveButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.loveButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.loveButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.loveButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.loveButton setImage:[UIImage imageNamed:@"iconfont-zan"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.loveButton];
        
        self.hateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.hateButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.hateButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.hateButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.hateButton setImage:[UIImage imageNamed:@"iconfont-cai"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.hateButton];
        
        self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.shareButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.shareButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.shareButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.shareButton setImage:[UIImage imageNamed:@"iconfont-fenxiang"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.shareButton];
        
        self.commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.commentButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.commentButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.commentButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.commentButton setImage:[UIImage imageNamed:@"iconfont-pinglun"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.commentButton];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.profile_imageView.frame = self.jokeFrameModel.profile_imageViewF;
    self.nameLabel.frame = self.jokeFrameModel.nameLabelF;
    self.createdLabel.frame = self.jokeFrameModel.createdLabelF;
    self.textLabell.frame = self.jokeFrameModel.textLabellF;
    self.loveButton.frame = self.jokeFrameModel.loveButtonF;
    self.hateButton.frame = self.jokeFrameModel.hateButtonF;
    self.shareButton.frame = self.jokeFrameModel.shareButtonF;
    self.commentButton.frame = self.jokeFrameModel.commentButtonF;
}
- (void)setJokeFrameModel:(TLST_jokeFrameModel *)jokeFrameModel{
    if (_jokeFrameModel != jokeFrameModel) {
        _jokeFrameModel = jokeFrameModel;
    }
    TLST_jokeModel *jokeModel = _jokeFrameModel.jokeModel;
    [self.profile_imageView sd_setImageWithURL:[NSURL URLWithString:jokeModel.profile_image] placeholderImage:[UIImage imageNamed:@"WplaceImage.jpg"]];
    self.nameLabel.text = jokeModel.name;
    self.createdLabel.text = [jokeModel.created_at substringToIndex:16];
    self.textLabell.text = jokeModel.text;
    [self.loveButton setTitle:jokeModel.love forState:UIControlStateNormal];
    [self.hateButton setTitle:jokeModel.hate forState:UIControlStateNormal];
    [self.shareButton setTitle:jokeModel.repost forState:UIControlStateNormal];
    [self.commentButton setTitle:[jokeModel.comment description] forState:UIControlStateNormal];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
